/**
 * 2015，thor.com，all rights reserved。
 * 
 * Project：		thor-common
 * Filename：	QueryResultConverter.java
 * Created：		2015年3月14日
 * Creator：		thor
 */
package com.thor.palmmall.hdmall.common;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.util.ConverterUtil;
import com.thor.commons.util.ExceptionUtil;

/**
 * @author thor
 *
 */
public class HDMQueryResultConverter {
	public static <S, T> com.thor.commons.query.QueryResult<T> convert(HDMQueryResult<S> source, Converter<S, T> converter) {
		if (source == null)
			return null;
		if (converter == null) {
			throw ExceptionUtil.nullArgument("converter");
		}

		com.thor.commons.query.QueryResult<T> target = new com.thor.commons.query.QueryResult<T>();
		target.setPage(source.getPage());
		target.setPageCount(source.getPageCount());
		target.setPageSize(source.getPageSize());
		target.setRecordCount(source.getRecordCount());
		target.setRecords(ConverterUtil.convert(source.getRecords(), converter));
		return target;
	}
}
